/*
 * Copyright © 2016 Cask Data, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

@import "../../../bower_components/bootstrap/less/mixins.less";
@import '../../styles/variables.less';
@import '../../styles/themes/cdap/mixins.less';

@type-column-width: 80px;
@fields-right-offset: 70px;
@disabled-input-bg-color: #eeeeee;

my-complex-schema {
  div.complex-schema-container {

    [class*="col-"] {
      padding-right: 0;
      padding-left: 7px;
    }

    fieldset.schema-fields-container {
      &.disabled {
        background-color: @disabled-input-bg-color;

        .tab-header-inner {
          background-color: @disabled-input-bg-color;
        }

        my-embedded-schema-selector {
          div.tab-toggle.expanded:before {
            background-color: @disabled-input-bg-color;
          }
        }
      }
    }

    .field-row {
      .form-control {
        background-color: transparent;
        border: 0;
        box-shadow: none;
        border-radius: 0;
        outline-offset: -4px;

        &.disabled {
          background-color: @disabled-input-bg-color;
        }

        .placeholder-color(@color: #666666, @font-weight: 500);
      }
      &:not(.nested-row) { box-shadow: 2px 0 2px 0 rgba(1, 0, 0, 0.2); }
    }
    .nested-row { border-top: 1px solid @table-border-color; }
    .type-column {
      width: @type-column-width;
      float: left;

      &.header { padding-left: 10px; }
    }

    .input-column {
      float: left;

      /**
       * 75px is the width of the checkbox, trash, and add button
       * 80px is the width of the type dropdown
       **/
      width: ~"-moz-calc(100% - 75px - 80px)";
      width: ~"-webkit-calc(100% - 75px - 80px)";
      width: ~"calc(100% - 75px - 80px)";

      &.no-type {
        width: ~"-moz-calc(100% - 75px - 80px)";
        width: ~"-webkit-calc(100% - 75px - 80px)";
        width: ~"calc(100% - 75px - 80px)";
      }

      .form-control {
        padding-left: 5px;
        text-indent: 2px;
      }

      &.header { padding-left: 4px; }
    }

    .select-wrapper {
      height: 33px;
      z-index: 100;
      .select-wrapper(@background-color: transparent, @arrow-color: @cdap-header, @right: 7px);
    }

    div.tab-header {
      border-radius: 4px 4px 0 0;
      box-shadow: rgba(1, 0, 0, 0.25) 0 0 10px;
      height: 26px;
      position: relative;
      z-index: 100;
      .form-control {
        height: 22px;
        padding: 0 5px;
      }
      div.tab-header-inner {
        border-radius: 4px 4px 0 0;
        height: 33px;
        div.select-wrapper {
          height: 26px;
          &:after { top: 5px; }
        }
      }
    }

    .error { color: @brand-danger; }

    .map-fields {
      width: 50px;
      line-height: 32px;
      padding-left: 5px;
    }

    .key-field,
    .value-field {
      .map-input-group.tab-header {
        .map-input-column { line-height: 32px; }
        .select-wrapper:after { top: -4px; }
      }
    }

    .map-input-group { display: inline-block; }
    .map-input-column { float: left; }

    .fields-actions {
      float: right;
      height: 33px;
      .nullable-header { margin-right: 42px; }

      .checkbox {
        width: 35px;
        margin-top: 7px;
        &.no-trash { margin-right: 25px; }
      }

      .actions-buttons {
        margin-top: -2px;
        width: 60px;
        padding-right: 10px;

        &.no-checkbox { margin-top: 7px; }
        .btn-link { padding: 0; }
        .fa-plus { color: #666666; }
      }
    }

    &.disabled {
      .input-column {
        /**
         * On disabled mode, there is not trash or plus button. Therefore only need to
         * substract 50px for the Null checkbox
         **/
        width: ~"-moz-calc(100% - 50px - 80px)";
        width: ~"-webkit-calc(100% - 50px - 80px)";
        width: ~"calc(100% - 50px - 80px)";
      }

      .fields-actions {
        .nullable-header { margin-right: 18px; }

        .checkbox,
        .checkbox.no-trash { margin-right: 0; }
      }

      my-embedded-schema-selector [class*="col-"]:after { width: 130px; }
    }
  }

  my-embedded-schema-selector {
    [class*="col-"] {
      box-shadow: 0 2px 3px 0 rgba(1, 0, 0, 0.1);
      position: relative;
      &:before {
        box-shadow: -2px 0 3px 0 rgba(1, 0, 0, 0.25);
        content: '';
        display: block;
        position: absolute;
        top: -8px;
        left: 0;
        bottom: 0;
        width: 1px;
      }
      &:after {
        box-shadow: 0 -2px 3px 0 rgba(1, 0, 0, 0.25);
        content: '';
        display: block;
        position: absolute;
        top: 0;
        right: 0;
        height: 1px;
        width: 100%;
      }
    }
    div.tab-toggle {
      position: relative;
      &.expanded:before {
        content: '';
        display: block;
        position: absolute;
        bottom: -3px;
        left: 0;
        height: 3px;
        z-index: 100;
        width: ~"-moz-calc(100% - 75px - 80px)";
        width: ~"-webkit-calc(100% - 75px - 80px)";
        width: ~"calc(100% - 75px - 80px)";
      }
    }
    span.fa {
      color: @hydrator-blue;
      position: absolute;
      z-index: 150;
      top: -15px;
      left: 5px;
      &:hover,
      &:focus { cursor: pointer; }
    }
    // Adjust caret position for map tab headers containing Key/Value
    div.map-schema-container {
      .key-field,
      .value-field {
        + my-embedded-schema-selector > div > div.tab-toggle span.fa { top: -12px; }
      }
    }
  }

  my-embedded-schema-selector my-record-schema > my-complex-schema > .complex-schema-container {
    .nested-row { border-top: 0; }
  }
}

.column-content > my-complex-schema > .complex-schema-container > fieldset > div.field-row:not(.nested-row) {
  box-shadow: -7px 0 6px -6px rgba(1, 0, 0, 0.25);
  margin-left: 4px;
}
